﻿//-----------------------------------------------------------------------
// <copyright file="IIdentityDataContract.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Silverlight.Contracts
{
    using System;

    using System.Runtime.Serialization;

    using System.Security;
    using System.Security.Principal;

    /// <summary>
    /// Defines the data contract representing the details of an identity.
    /// </summary>
    [DataContract(Name = "IIdentityDataContract", Namespace = "http://schemas.datacontract.org/2004/07/CodePlex.Diagnostics.Contracts")]
    public sealed class IIdentityDataContract
    {
        #region public IIdentityDataContract(IIdentity identity)

        /// <summary>
        /// Initializes a new instance of the <see cref="T:IIdentityDataContract"/> class.
        /// </summary>
        /// <param name="identity">The <see cref="T:System.Security.Principal.IIdentity"/> for which the <see cref="T:CodePlex.Diagnostics.Contracts.IIdentityDataContract"/> is required.</param>
        public IIdentityDataContract(IIdentity identity)
        {
            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }

            this.AuthenticationType = identity.AuthenticationType;

            this.IsAuthenticated = identity.IsAuthenticated;

            this.Name = identity.Name;

            this.SerializedIIdentity = null;
        }

        #endregion

        #region public string AuthenticationType

        /// <summary>
        /// Gets the type of authentication used.
        /// </summary>
        /// <value>The type of authentication used to identify the user.</value>
        [DataMember]
        public string AuthenticationType
        {
            get;
            private set;
        }

        #endregion

        #region public bool IsAuthenticated

        /// <summary>
        /// Gets a value indicating whether the user has been authenticated.
        /// </summary>
        /// <value><c>true</c> if the user was authenticated; otherwise, <c>false.</c></value>
        [DataMember]
        public bool IsAuthenticated
        {
            get;
            private set;
        }

        #endregion

        #region public string Name

        /// <summary>
        /// Gets the name of the current user.
        /// </summary>
        /// <value>The name of the user on whose behalf the code is running.</value>
        [DataMember]
        public string Name
        {
            get;
            private set;
        }

        #endregion

        #region public string SerializedIIdentity

        /// <summary>
        /// Gets a <see cref="T:System.String"/> containing the soap-encoded serialized <see cref="T:System.Security.Principal.IIdentity"/> instance.
        /// </summary>
        /// <value>A <see cref="T:System.String"/> containing the soap-encoded serialized <see cref="T:System.Security.Principal.IIdentity"/> instance.</value>
        [DataMember]
        public string SerializedIIdentity
        {
            get;
            set;
        }

        #endregion

        #region public IIdentity DeserializedIdentity

        /// <summary>
        /// Gets the deserialized <see cref="T:System.Security.Principal.IIdentity"/> instance.
        /// </summary>
        /// <value></value>
        public IIdentity DeserializedIdentity
        {
            get
            {
                return null;
            }
        }

        #endregion
    }
}